﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XStudio.XCRF.Web.Controllers;

namespace XStudio.XCRF.Web.Extensions
{
    public static class UrlExtensions
    {
        /// <summary>
        /// 获取上个页面的URL，如果不存在则返回主页URL
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string LastURL(this UrlHelper urlhelper)
        {
            string url;
            HttpRequest request = HttpContext.Current.Request;
            Uri uri = request.UrlReferrer;
            if (uri == null)
                url = urlhelper.Action<HomeController>(c => c.Index());
            else
                url = uri.ToString();
            return url;
        }
    }
}